// physical node: a master crate serving as both mc and cmc
// Created: Nov. 6, 2024 by SUN Yazhou, asia.rabbit@163.com

#include "SMC.h"
#include "LN.h"

SMC::SMC(const YAML::Node &n) : PN(n, CRATE_SMC){}

SMC::~SMC(){}

// configure all the lns
void SMC::Ln(){
  LN *ds0 = data_save(0), *sc1 = sys_console_gui(1);
  // data stream //
  LN *ri2 = reduce_index(2, DATA);
  *ri2 >> *ds0;
  // cmd stream //
  LN *mi3 = map_index(3, CMD);
  *sc1 >> *mi3;
  // status stream //
  LN *ri4 = reduce_index(4, STA);
  *ri4 >> *sc1;

  LN *mt5 = master_trigger(5, fn["master_trigger"].as<string>());
  LN *st6 = slave_trigger(6, fn["slave_trigger"].as<string>());
  *mt5 >> *ri4; *st6 >> *ri4; // status stream
  *mi3 >> *mt5; *mi3 >> *st6; // cmd stream

  for(auto t : fn["dsi"]){
    LN *dsii = dsi(nl(), t.as<string>());
    // data-cmd-sta: the order is mandatory
    *dsii >> *ri2; *mi3 >> *dsii; *dsii >> *ri4;
  } // end for over dsi-s
  
  // assign interfacing ports //
  fRiData = ri2; fMiCmd = mi3; fRiSta = ri4;
} // end member function Ln
